Skip to main content

Full text of "Arduino"

See other formats


Read & Write Flash Contents of Your Arduino or AVR Chip 



i 



Make Projects 



build, hack, tweak, share, discover. 



Read & Write Flash Contents of 



Your Arduino or AVR Chip 



Written By: Ben L 



TOOLS: 



Arduino Duemilanove or Diavolino (UNO 
is iffy and not recommended) (1) 

Computer running Linux, Windows, or 
MacOSXm 

Evil Mad Scientist's ISP Shield 2.0, or 
any AVR ISP (In System Programmer) 

USB A to B cabled) 



PARTS: 

ATMega328p (1) 



SUMMARY 

Need to burn Arduino bootloaders onto lots of Arduinos or AVR chips? Avrdude is the perfect 
tool to configure and burn those things REALLY fast! Plus it's terminal-based and easily 
scriptable. I'll show you how to bend Avrdude to your will! 



© Make Projects 



www.makeprojects.com 



Page 1 of 10 



Read & Write Flash Contents of Your Arduino or AVR Chip 



Step 1 — Read & Write Flash Contents of Your Arduino or AVR Chip 

• First we have to install Avrdude. 
This method will vary based on 
your operating system, as we'll see 
below: 

• For Windows, an executable can 
be found here . 

• For Mac OSX, I recommend 
following the instructions here . 

• For Linux, your distro may have it 
in its repository. If you're an Arch 
Linux user, it can be found in the 
AUR as avrdude-arduino. 

• As I am an Arch Linux user, my 
initial screenshots will be Arch- 
based. I'll expand to Windows and 
perhaps OSX later. 




Step 2 




• Now we're going to show you how 
to get to Avrdude, which also 
varies by operating system. 

• For Windows, type "cmd" in the 
Run dialog. Type "avrdude" into the 
terminal. If it installed sucessfully, 
it should show you a list of options. 

• For OSX, open Terminal and type 
"avrdude". A list of options should 
appear 

• And with Linux, just open a 
terminal and type "avrdude" and a 
list will appear. Like magic. 



© Make Projects 



www.makeprojects.com 



Page 2 of 10 



Read & Write Flash Contents of Your Arduino or AVR Chip 



Step 3 




• Now we're going to connect our 
AVR ISP programmer to the 
computer. The steps vary 
somewhat based on the 
programmer, but I will show you 
how to use Evil Mad Scientist's ISP 
Shield 2.0 on top of an Arduino 
Duemilanove. 

• Currently, this method may 
not work with Arduino UNOs 
without some modifications. This is 
because of the bootloader used on 
the UNO. 

• If you feel like trying, according to 
this site it may work with a 10uF 
capacitor connected between reset 
and ground. Or it may work 
unedited, I haven't tested it yet 



© Make Projects 



www.makeprojects.com 



Page 3 of 10 



Read & Write Flash Contents of Your Arduino or AVR Chip 



Step 4 



© Make Projects www.makeprojects.com Page 4 of 1 



Read & Write Flash Contents of Your Arduino or AVR Chip 




• Now we're going to invoke the 
Avrdude command to do 
something; in this case copy the 
flash contents of an ATmega328p 
chip to a file named "flash.bin" in 
the current directory. 

• In the screenshot we see the 
command being invoked, avrdude 
runs the command, while -p 

m32 8p tells Avrdude we're 
programming an ATmega328p chip. 

• -p tells Avrdude where to look for 
the USB programmer. On my Linux 
computer, it's at /dev/ttyUSBO. 

• On Windows, the command used 
is based on the programmer being 
used. If it's USB-based, than you 
can put usb after -p, if it's on a 
parallel port it's probably LPT1, or if 
it's serial, COM1. If you can't find 

it, you can always look in Device 
Manager to find out. 

• OSX users have it tough. If you 
have the Arduino IDE installed, 
look under the serial ports option 
and see where your Arduino is 

• The stuff after -c is the 
programmer you're using. For the 
ISP Shield 2.0, use avrisp. Look 
at the documentation on yours to 
find out. 

• Penultimately, the number after -b 
is the new baud rate. I could only 
get the ISP Shield 2.0 on a 
Duemilanove to work with a rate of 
19200. Common baud rates also 



© Make Projects 



www.makeprojects.com 



Page 5 of 10 



Read & Write Flash Contents of Your Arduino or AVR Chip 

include 9600. Leave this option off 
and see if it works. If it doesn't 
work, and you have the right 
programmer location, try the two 
above. Otherwise, Google is your 
friend. 

• And finally -u 

f lash: r : f lash, bin: r is the 
command for reading the flash 
memory and saving it in raw format 
to "flash.bin". Replacing 
flash:r:flash.bin:r with 
flash:w:flash.bin will write 
the contents of "flash.bin" to the 
chip 



© Make Projects www.makeprojects.com Page 6 of 1 



Read & Write Flash Contents of Your Arduino or AVR Chip 



Step 5 





The last thing to worry about, once Avrdude has run succesfully, is the fuse values. These 
should only be trifled with if your Arduino or chip is not working. I had to change them on 
some blank 328p chips. The best thing to do is plug it in and test it with the Blink sketch. If 
it doesn't work, then you might have to change the fuses. Proceed to the next step: 

The fuses are kind of like the config values for the chip itself. They control the speed, 
voltage, and type of clock used in the chip. Changing these is not difficult, but it is not for 
the foolhardy. I burned one 328p chip with the Blink sketch, and used Avrdude to check the 
fuses. 

Command for viewing fuses on my computer: avrdude -p m328p -p /dev/ttyUSBO 
-c avrisp -b 19200 -v 

In the screenshot, you can see the results of two different chips. To show the date, just 
replace the -u option and everything after it with -v. That will only show you info about the 
chip, not change it 

On the top is the results from a chip that successfully runs Blink. The bottom one does 
not. 

To change the fuses we only need to go to a calculator, like this one . Choose your chip, 
and enter the values of Ifuse, efuse, and hfuse shown in the screenshot into the bottom of 
the page under "Current settings". 

It will generate new -u values which can be added to the end of your command after the - 
u flash : w : flash . bin. An unlimited number of -u commands can be chained. You can 
run Avrdude with the -v command again to verify the fuse values. 



© Make Projects 



www.makeprojects.com 



Page 7 of 10 



Read & Write Flash Contents of Your Arduino or AVR Chip 



Step 6 



© Make Projects www.makeprojects.com Page 8 of 1 



Read & Write Flash Contents of Your Arduino or AVR Chip 




Finally, here's the full command for 
copying the contents of the chip 
AND changing the fuse values to 
the correct ones: 



-v 



• avrdude -p m328p -P 
/dev/ttyUSBO -c avrisp 
-b 19200 -U 

f lash :w: flash .bin -U 
If use : w: Oxf f :m -U 
hf use : w: Oxda :m -U 
ef use : w: 0x05 :m 

• This copies the contents of 
"flash.bin" to the chip, and 
overwrites the fuses. The eagle- 
eyed among you will notice the 
addition of -v, which tells Avrdude 
not to verify the process, and cuts 
the time from 30 seconds to a 
shocking 2.24 seconds per chip. 
Use at your own risk, of course. 

• Finally, if you'd like additional 
information, or are still somewhat 
confused, these links may aid you: 
http://arduino.cc/en/Tutorial/ArduinolSP 
http://www.ladyada.net/learn/avr/avrdude. 
http://www.evi lmadscientist.com/article. . . . 
http://www.ladyada.net/learn/avr/fuses-h. . 

• Note though, that Avrdude is only 
really worth it if you have large 
numbers of chips (or boards) to 
burn. The Arduino software can 
easily do all this stuff, albeit slower 
and not as scriptable. But a lot 
easier. 



© Make Projects 



www.makeprojects.com 



Page 9 of 10 



Read & Write Flash Contents of Your Arduino or AVR Chip 

I hope this has helped you understand the use of Avrdude for mass burning of chips. Again, this 
is only worthwhile if you have a large quantity, or want a scriptable method of Arduino 
management. Using the Arduino software is far easier for small numbers of jobs. If anything is 
unclear, don't hesitate to comment, and I'll see what I can do. 

This document was last generated on 2012-11-03 03:05:15 AM. 



© Make Projects www.makeprojects.com Page 10 of 10